<?php
namespace bee;
class option extends widget
{
  public $onChangeFn;
  public $listOfValues;
  public $notSelectedText = "choose value";
  public $notSelectedValue = -1;
  function __construct($name, &$bindValue = "", $list = NULL, $listFieldName= "value", $listKeyName = "id")
  { if($list)
    {  $this->setList($list, $listFieldName, $listKeyName);
    }

    $this->bindValue($bindValue);
    parent::__construct($name);
  }

  public function onDraw($evt)
  { $this->fillDSDoc();

  }
  public function setList($list, $listFieldName= "value", $listKeyName = "id")
  { $this->listOfValues = null;
    if(is_array($list))
    { $this->listOfValues = $list;
    } else if(is_a($list, "bee\\rowSet"))
    { $this->listOfValues = $list->getList($listFieldName, $listKeyName);
    } else if(is_subclass_of($list, "bee\\DAO"))
    { $rs = new rowSet(clone $list);
      $this->listOfValues = $rs->getList($listFieldName, $listKeyName);
    } else
    { echo __FILE__ . " / " . __CLASS__ . " (id: " . $this->id . ") red: " . __LINE__ . " error no list:" . print_r($list, true);
    }
  }

  public function fillDSDoc($fillVar = "")
  {
    $__DSDoc = XMLDataHub::getInstance();
    $__DSDoc->setArray($this->listOfValues, $this->name);
    if($fillVar)
    { $__DSDoc->setVariable($fillVar, $this->value);
    }
    //echo "drw Opt $this->name";
    if($this->drawMe)
    { $__DSDoc->setObject("/form/widgets/". $this->name, $this);
    }
  }

}